package com.szqhyxj.youxiangju.biz.core

import android.annotation.SuppressLint
import android.app.Activity
import android.content.SharedPreferences

object TokenManager {

    var mToken = ""

    lateinit var preferences: SharedPreferences

    const val KEY = "TOKEN"

    @SuppressLint("ApplySharedPref")
    fun setToken(token: String) {
        mToken = token
        preferences.edit().putString(KEY, token).commit()
    }

    @SuppressLint("ApplySharedPref")
    fun clear() {
        mToken = "";
        preferences.edit().clear().commit();
    }

    fun init(app: App) {
        preferences = app.getSharedPreferences("TOKEN", Activity.MODE_PRIVATE)
        preferences.getString(KEY, "")?.let {
            mToken = it
        }
    }

    fun online(): Boolean {
        return !mToken.isEmpty()
    }
}